<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="f" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath }/css/css.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath }/jquery/jquery-1.8.2.js"></script>
<title>Insert title here</title>
</head>
<body>
	<f:form action="add" method="post" modelAttribute="roll" enctype="Multipart/form-data">
	<h1>发薪单</h1>
	发薪单名称:<f:input path="rname"/><br>
	所属组织:
	<f:select path="comid" onchange="change1()">
	<f:option value="">请选择</f:option>
	</f:select><br>
	所属事业部:
	<f:select path="busid" onchange="change2()">
	<f:option value="">请选择</f:option>
	</f:select><br>
	所属部门:
	<f:select path="deptid">
	<f:option value="">请选择</f:option>
	</f:select><br>
	发放总金额:<f:input path="account"/><br>
	计税标准文件:<input type="file" name="file">
	
	<h1>发薪人员</h1>
	<input type="button" value="增加发薪人员" onclick="zj()"><br><br>
	
	<span class="s1">
	员工姓名:<input type="text" name="paymasters[0].name">
	员工类别:
	<select name="paymasters[0].types">
	<option value="">请选择</option>
	<c:forEach items="<%=com.xirui.bean.Gender.values() %>" var="G">
	<option value="${G.id }" >${G.name }</option>
	</c:forEach> 
	</select>
	发放金额:<input type="text" name="paymasters[0].price">
	<input type="button" value="删除" onclick="sc()"><br><br>
	</span><br><br>
	
	<f:button>提交</f:button>
	</f:form>

<script type="text/javascript">
var count =1;
function zj(){
	
	$(".s1").append(
			"<span >"+
			"员工姓名:<input type='text' name='paymasters["+count+"].name'>"+
			"员工类别:"+
			"<select name='paymasters["+count+"].types'>"+
			"<option value=''>请选择</option>"+
			"<c:forEach items='<%=com.xirui.bean.Gender.values() %>' var='G'>"+
			"<option value='${G.id }' >${G.name }</option>"+
			"</c:forEach>"+
			"</select>"+
			"发放金额:<input type='text' name='paymasters["+count+"].price'>"+
			"<input type='button' value='删除' onclick='sc(this)' >"+
			"</span><br><br>"
			)
			count++;
}
function sc(thiz){
	$(thiz).parent().remove();
	
}



	$.post(
		"sanji",
		{id:0},
		function(msg){
			for (var i = 0; i < msg.length; i++) {
				$("[name='comid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
			}
			$("[name='comid']").val('${roll.comid}')
			$("[name='comid']").trigger("change")
		},
		"json"
	)

	function change1(){
		var id=$("[name='comid']").val();
		$.post(
				"sanji",
				{id:id},
				function(msg){
					for (var i = 0; i < msg.length; i++) {
						$("[name='busid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
					}
					$("[name='busid']").val('${roll.busid}')
					$("[name='busid']").trigger("change")
				},
				"json"
			)
	}
	function change2(){
		var id=$("[name='busid']").val();
		$.post(
				"sanji",
				{id:id},
				function(msg){
					for (var i = 0; i < msg.length; i++) {
						$("[name='deptid']").append("<option value='"+msg[i].id+"'>"+msg[i].name+"</option>")
					}
					$("[name='deptid']").val('${roll.deptid}')
				},
				"json"
			)
	}





</script>
</body>
</html>